//
//  ITMapTableViewController.m
//  InduceTool
//
//  Created by 魏延龙 on 2020/9/22.
//  Copyright © 2020 魏延龙. All rights reserved.
//

#import "ITMapTableViewController.h"
#import "MapModel.h"

@interface ITMapTableViewController ()

// 可以用对象做key
@property (nonatomic, strong) NSMapTable *mapTable;

@end

@implementation ITMapTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    MapModel *model = [[MapModel alloc] init];
    model.name = @"aa";
    model.des = @"bb";

    self.mapTable = [NSMapTable strongToWeakObjectsMapTable];
    [self.mapTable setObject:@"value" forKey:model];

    [self setupViews];

    extern int globalVar;
    NSLog(@"--globalVar:%d",globalVar);
}

- (void)setupViews {
    UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [startBtn setTitle:@"输出" forState:UIControlStateNormal];
    startBtn.frame = CGRectMake(50, 200, 100, 44);
    [self.view addSubview:startBtn];
    [startBtn addTarget:self action:@selector(startAction) forControlEvents:UIControlEventTouchUpInside];

    UIButton *ratorBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [ratorBtn setTitle:@"遍历" forState:UIControlStateNormal];
    ratorBtn.frame = CGRectMake(50, 250, 100, 44);
    [self.view addSubview:ratorBtn];
    [ratorBtn addTarget:self action:@selector(ratorAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)startAction {
    NSLog(@"result: %@", self.mapTable);
}

- (void)ratorAction {
    NSArray *iosArray = @[@"L", @"O", @"V", @"E", @"I", @"O", @"S"];
//    NSEnumerator *enumerator = [iosArray objectEnumerator];//正向遍历
    NSEnumerator *enumerator = [iosArray reverseObjectEnumerator];//反向遍历
    id object;
    while ((object = [enumerator nextObject]) != nil)
        //处理枚举器中的数据
        NSLog(@"%@", object);
}

@end
